package com.zn.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zn.entity.*;
import com.zn.mapper.*;
import com.zn.service.PayChannelService;
import com.zn.util.*;
import com.zn.vo.Message;
import com.zn.vo.PayMethodVo;
import com.zn.vo.Response;
import com.zn.web.dto.*;
import com.zn.web.rpc.PayRemoteCall;
import com.zn.web.vo.CustomerCapitalVo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * Created by yinjiawei on 2018/8/1.
 */
@Service
public class PayChannelServiceImpl implements PayChannelService {
    private static final Logger LOGGER = LoggerFactory.getLogger(PayChannelServiceImpl.class);
    @Autowired
    private CustomerBankInfoMapper customerBankInfoMapper;
    @Autowired
    private CustomerUnderlineRechargeMapper customerUnderlineRechargeMapper;
    @Autowired
    private AppCustomerMapper appCustomerMapper;
    @Autowired
    private CustomerWithdrawMapper customerWithdrawMapper;
    @Autowired
    private RechargeRateMapper rechargeRateMapper;
    @Autowired
    private CustomerOnlineRechargeMapper customerOnlineRechargeMapper;
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Autowired
    private PayRemoteCall payRemoteCall;
    @Value("${zhifuqiao.mchid}")
    private String mchid;


    @Override
    public List<PayMethodVo> selectPayChannel(String payType){
        try {
            Response response = payRemoteCall.getActionMethod(payType);
            if(!response.isSuccess()){
                throw new Exception("支付桥接口状态返回失败......");
            }
            List<PayMethodVo> payMethodVoList=response.getData();
            this.saveRedisFee(payMethodVoList,payType);
            return payMethodVoList;
        }catch (Exception e){
            LOGGER.error("selectPayChannel---------->"+e.getMessage());
            return null;
        }
    }
    /**
     * 线下充值
     * @param filePath 凭证url
     * @param underLineRechargeDto form表单值
     */
    @Transactional
    @Override
    public ResponseEntity<Message> underLineRecharge(String filePath, UnderLineRechargeDto underLineRechargeDto) {
        AppCustomer appCustomer=appCustomerMapper.selectByPrimaryKey(underLineRechargeDto.getCustomerId());
        if(appCustomer==null){
            return ResponseEntity.ok(Message.ARGS_ERROR);
        }
        CustomerUnderlineRecharge customerUnderlineRecharge=new CustomerUnderlineRecharge();
        customerUnderlineRecharge.setUnderlineRechargeId(UUIDUtils.getUuid());
        customerUnderlineRecharge.setCustomerId(underLineRechargeDto.getCustomerId());
        customerUnderlineRecharge.setPayee(underLineRechargeDto.getPayee());
        customerUnderlineRecharge.setReceivablesAccount(underLineRechargeDto.getReceivablesAccount());
        customerUnderlineRecharge.setReceivablesBank(underLineRechargeDto.getReceivablesBank());
        customerUnderlineRecharge.setTransferAccountsBank(underLineRechargeDto.getTransferAccountsBank());
        customerUnderlineRecharge.setBankCard(underLineRechargeDto.getBankCard());
        customerUnderlineRecharge.setCardholderName(underLineRechargeDto.getCardholderName());
        customerUnderlineRecharge.setRechargeAmount(underLineRechargeDto.getRechargeAmount());
        customerUnderlineRecharge.setReceivablesNumber(underLineRechargeDto.getReceivablesNumber());
        customerUnderlineRecharge.setAuditStatus(0);
        customerUnderlineRecharge.setVoucherPic(filePath);
        customerUnderlineRecharge.setCreateTime(new Date());
        customerUnderlineRechargeMapper.insertSelective(customerUnderlineRecharge);
        //将唯一标识放入redis中
        redisTemplate.opsForValue().set(Constant.IDEMPOTENCY_UNDERLINERECHARGE+underLineRechargeDto.getCustomerId(),underLineRechargeDto.getIdempotency());
        redisTemplate.expire(Constant.IDEMPOTENCY_UNDERLINERECHARGE+underLineRechargeDto.getCustomerId(),5, TimeUnit.MINUTES);
        return ResponseEntity.ok(Message.REQ_SUCCESS);
    }

    @Override
    public ResponseEntity<Message> clickWithdraw(PayChannelDto payChannelDto) throws Exception{
        CustomerWithdraw customerWithdrawParam=new CustomerWithdraw();
        customerWithdrawParam.setCustomerId(payChannelDto.getCustomerId());
        customerWithdrawParam.setAuditStatus(0); //未审核
        customerWithdrawParam.setWithdrawStatus(3); //未发起
        List<CustomerWithdraw> customerWithdrawList=customerWithdrawMapper.selectBySqlWhere(customerWithdrawParam);
        if(customerWithdrawList.size()>0){
            //存在未审核订单
            return ResponseEntity.ok(Message.WITHDRAW_EXIST_UNAUDITED);
        }
        String nowDateStr= DateUtils.convertDateToString(new Date());
        Map<String,Object> map=customerWithdrawMapper.countWithdrawData(payChannelDto.getCustomerId(), nowDateStr);
        RechargeRate rechargeRate=rechargeRateMapper.selectByRechargeType(1);
        Integer sumWithdrawNun=Integer.valueOf(map.get("sumWithdrawNun").toString());
        Double sumWithdrawAmount=Double.valueOf(map.get("sumWithdrawAmount").toString());
        //如果当日提现次数>日次数
        if(rechargeRate.getRechargeFiurnalFrequency()!=0 && sumWithdrawNun>=rechargeRate.getRechargeFiurnalFrequency()){
            //提示当日提现次数已使用完
            return ResponseEntity.ok(Message.WITHDRAW_NUMBER_USE);
        }
        //当日累计提现金额+该笔提现金额>日累计限额
        if(rechargeRate.getRechargeAggregate() != 0 && sumWithdrawAmount>=rechargeRate.getRechargeAggregate()){
            //提示超过日累计限额
            return ResponseEntity.ok(Message.WITHDRAW_EXCEED_QUOTA);
        }
        List<CustomerBankInfo> customerBankInfoList =customerBankInfoMapper.selectByCustomerId(payChannelDto.getCustomerId());
        return ResponseEntity.ok(Message.successData(customerBankInfoList));
    }

    @Transactional
    @Override
    public ResponseEntity<Message> onLineRecharge(OnLineRechargeDto onLineRechargeDto) {
        AppCustomer appCustomer=appCustomerMapper.selectByPrimaryKey(onLineRechargeDto.getCustomerId());
        /**获取入金的最高最低手续费**/
        RechargeRate rechargeRate=rechargeRateMapper.selectByRechargeType(2);
        /**获取通道费率 计算手续费**/
        String PayMethodVo="";
        LOGGER.info("onLineRechargeDto.getPayMethod():"+onLineRechargeDto.getPayMethod()+";onLineRechargeDto.getCustomerId():"+onLineRechargeDto.getCustomerId());
        if(1==Integer.valueOf(onLineRechargeDto.getPayMethod())){
            PayMethodVo=(String)redisTemplate.opsForHash().get(Constant.PAY_METHOD_KEY_GATEWAY, onLineRechargeDto.getAccountName());
        }else if(2==Integer.valueOf(onLineRechargeDto.getPayMethod())){
            PayMethodVo=(String)redisTemplate.opsForHash().get(Constant.PAY_METHOD_KEY_QUICK, onLineRechargeDto.getAccountName());
        }
        JSONObject json = JSONObject.parseObject(PayMethodVo);
        Integer feeType=Integer.valueOf(json.get("feeType").toString());
        Double fee=Double.valueOf(json.get("fee")==null?"0":json.get("fee").toString());
        //充值金额>单笔最高限额
        if(onLineRechargeDto.getRechargeAmount()>rechargeRate.getRechargeEachcCeiling()){
            //充值金额超出单笔最高限额
            return ResponseEntity.ok(Message.SINGLE_MAXIMUM_QUOTA);
        }
        //充值金额<单笔最低限额
        if(onLineRechargeDto.getRechargeAmount()<rechargeRate.getRechargeEachcFloor()){
            //充值金额小于单笔最低限额
            return ResponseEntity.ok(Message.SINGLE_MINIMUM_QUOTA);
        }
        /**计算该笔充值手续费**/
        Double rechargeSxf=0.0;
        //按百分比收取手续费
        if(feeType==2){
            rechargeSxf=onLineRechargeDto.getRechargeAmount()*fee;
            LOGGER.info("rechargeSxf befron.........."+rechargeSxf);
            if(rechargeSxf>rechargeRate.getRechargeMaxCharge()){
                rechargeSxf=rechargeRate.getRechargeMaxCharge();
            }
            if(rechargeSxf<rechargeRate.getRechargeMinCharge()){
                rechargeSxf=rechargeRate.getRechargeMinCharge();
            }
            LOGGER.info("rechargeSxf after.........."+rechargeSxf);
        }
        //按每笔绝对值收
        if(feeType==1){
            rechargeSxf=fee;
        }
        if(rechargeSxf>=onLineRechargeDto.getRechargeAmount()){
            return ResponseEntity.ok(Message.RECHARGE_INSUFFICIENT_POUNDAGE);
        }
        /**封装调用接口需要dto**/
        VerifyDto verifyDto=new VerifyDto();
        verifyDto.setAction(Integer.valueOf(onLineRechargeDto.getAccountId()));
        Integer payStatus=json.getInteger("payStatus");
        /**快捷拿卡信息**/
        if(onLineRechargeDto.getPayMethod()==2 && payStatus == 1 ){
            CustomerBankInfo customerBankInfo=customerBankInfoMapper.selectByPrimaryKey(onLineRechargeDto.getBankInfoId(),onLineRechargeDto.getCustomerId());
            if(customerBankInfo==null){
                //当前卡不存在
                return ResponseEntity.ok(Message.CUSTOMER_BANK_NOT_FOUND);
            }
            verifyDto.setBankCode(customerBankInfo.getBankCode());
            verifyDto.setBranches(customerBankInfo.getOpeningBank());
            verifyDto.setName(customerBankInfo.getCardholderName());
            verifyDto.setNumberId(customerBankInfo.getCardholderIdCard());
            verifyDto.setTel(customerBankInfo.getCardholderTel());
            verifyDto.setCardNo(customerBankInfo.getBankNo());
        }else if(onLineRechargeDto.getPayMethod()==1){
            verifyDto.setBankCode(onLineRechargeDto.getBankCode());
            verifyDto.setBranches(onLineRechargeDto.getOpeningBank());
            verifyDto.setName(appCustomer.getName());
            verifyDto.setNumberId(appCustomer.getIdCard());
            verifyDto.setTel(appCustomer.getCustomerTel());
        }
        verifyDto.setMoney(onLineRechargeDto.getRechargeAmount());
        verifyDto.setUid(onLineRechargeDto.getCustomerId());
        /**规则yyyyMMddHHmmss+000000**/
        String tradeNo=DateUtils.getDate(new Date())+getPayNum();
        verifyDto.setTradeNo(tradeNo);
        verifyDto.setPayMethod(onLineRechargeDto.getPayMethod());
        verifyDto.setApi(json.getString("api"));
        Response response=payRemoteCall.verifyMethod(verifyDto);
        if(!response.isSuccess()){
            Message message=new Message("605",response.getResultMessage());
            return ResponseEntity.ok(message);
        }
        CustomerOnlineRecharge customerOnlineRecharge=new CustomerOnlineRecharge();
        customerOnlineRecharge.setOnlineRechargeId(UUIDUtils.getUuid());
        customerOnlineRecharge.setCustomerId(onLineRechargeDto.getCustomerId());
        customerOnlineRecharge.setBankInfoId(onLineRechargeDto.getBankInfoId());
        customerOnlineRecharge.setTradeNo(tradeNo);
        customerOnlineRecharge.setRechargeAmount(onLineRechargeDto.getRechargeAmount());
        customerOnlineRecharge.setActionId(onLineRechargeDto.getAccountId());
        customerOnlineRecharge.setActionName(onLineRechargeDto.getAccountName());
        customerOnlineRecharge.setPayMethod(onLineRechargeDto.getPayMethod());
        customerOnlineRecharge.setMchId(mchid);
        customerOnlineRecharge.setCreateTime(new Date());
        customerOnlineRecharge.setPoundage(rechargeSxf);
        /**接口调用结果填充**/
        customerOnlineRecharge.setRechargeStatus(4);
        customerOnlineRecharge.setRechargeStatusMsg(response.getResultMessage());
        customerOnlineRecharge.setRechargeOrderNum(response.getOrderNum());
        customerOnlineRechargeMapper.insertSelective(customerOnlineRecharge);
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("url",response.getUrl());
        Message message=Message.successData(map);
        message.setMsg(response.getResultMessage());
        return ResponseEntity.ok(message);
    }

    /**
     * 客户提现
     * @param customerWithdrawDto
     * @return
     */
    @Transactional
    @Override
    public ResponseEntity<Message> customerWithdraw(CustomerWithdrawDto customerWithdrawDto) {
        AppCustomer appCustomer=appCustomerMapper.selectByPrimaryKey(customerWithdrawDto.getCustomerId());
        if(appCustomer==null){
            return ResponseEntity.ok(Message.ARGS_ERROR);
        }
        /**如果是提现 则进来就开始校验密码是否一致 1-提现 2-提现校验**/
        if(customerWithdrawDto.getWithdrawType()==1){
            if(StringUtils.isBlank(customerWithdrawDto.getCustomerCapitalPassword())){
                return ResponseEntity.ok(Message.ARGS_ERROR);
            }
            /**校验密码是否一致**/
            String md5Password= EnDecryptUtil.MD5(appCustomer.getCustomerTradeAccount() + customerWithdrawDto.getCustomerCapitalPassword());
            if(!md5Password.equals(appCustomer.getCustomerCapitalPassword())){
                //密码不一致
                return ResponseEntity.ok(Message.ACCOUNT_CAPITAL_PASSWORD_MISMATCH);
            }
        }
        CustomerWithdraw customerWithdrawParam=new CustomerWithdraw();
        customerWithdrawParam.setCustomerId(customerWithdrawDto.getCustomerId());
        customerWithdrawParam.setAuditStatus(0); //未审核
        customerWithdrawParam.setWithdrawStatus(3); //未发起
        List<CustomerWithdraw> customerWithdrawList=customerWithdrawMapper.selectBySqlWhere(customerWithdrawParam);
        if(customerWithdrawList.size()>0){
            //存在未审核订单
            return ResponseEntity.ok(Message.WITHDRAW_EXIST_UNAUDITED);
        }
        String nowDateStr= DateUtils.convertDateToString(new Date());
        Map<String,Object> map=customerWithdrawMapper.countWithdrawData(customerWithdrawDto.getCustomerId(), nowDateStr);
        RechargeRate rechargeRate=rechargeRateMapper.selectByRechargeType(1);
        Integer sumWithdrawNun=Integer.valueOf(map.get("sumWithdrawNun").toString());
        Double sumWithdrawAmount=Double.valueOf(map.get("sumWithdrawAmount").toString());
        //如果当日提现次数>日次数
        if(rechargeRate.getRechargeFiurnalFrequency() != 0 && sumWithdrawNun>=rechargeRate.getRechargeFiurnalFrequency()){
            //提示当日提现次数已使用完
            return ResponseEntity.ok(Message.WITHDRAW_NUMBER_USE);
        }
        //当日累计提现金额+该笔提现金额>日累计限额
        if(rechargeRate.getRechargeAggregate()!=0 && (sumWithdrawAmount+customerWithdrawDto.getWithdrawAmount())>=rechargeRate.getRechargeAggregate()){
            //提示超过日累计限额
            return ResponseEntity.ok(Message.WITHDRAW_EXCEED_QUOTA);
        }
        //提现金额>单笔最高限额
        if(rechargeRate.getRechargeEachcCeiling() != 0 &&customerWithdrawDto.getWithdrawAmount()>rechargeRate.getRechargeEachcCeiling()){
            //提现金额超出单笔最高限额
            return ResponseEntity.ok(Message.SINGLE_MAXIMUM_QUOTA);
        }
        //提现金额<单笔最低限额
        if(rechargeRate.getRechargeEachcFloor() !=0 && customerWithdrawDto.getWithdrawAmount()<rechargeRate.getRechargeEachcFloor()){
            //提现金额小于单笔最低限额
            return ResponseEntity.ok(Message.SINGLE_MINIMUM_QUOTA);
        }
        /**计算该笔提现手续费**/
        /*Double withdrawSxf=0.0;
        //按百分比收取手续费
        if(rechargeRate.getRechargePoundageType()==2){
            withdrawSxf=customerWithdrawDto.getWithdrawAmount()*rechargeRate.getRechargeEachcChargeRate();
            if(withdrawSxf>rechargeRate.getRechargeMaxCharge()){
                withdrawSxf=rechargeRate.getRechargeMaxCharge();
            }
            if(withdrawSxf<rechargeRate.getRechargeMinCharge()){
                withdrawSxf=rechargeRate.getRechargeMinCharge();
            }
        }
        //按每笔绝对值收
        if(rechargeRate.getRechargePoundageType()==1){
            withdrawSxf=rechargeRate.getRechargeEachcFixedRate();
        }*/
        /**计算可用资金**/
        Double availableFunds=appCustomer.getCustomerCapital()-appCustomer.getCustomerFreezeCapital();
        if(availableFunds<customerWithdrawDto.getWithdrawAmount()){
            //可用资金不足
            return ResponseEntity.ok(Message.LACK_OF_FUNDS);
        }
        /**如果是校验 上面的全通过后 则返回成功 1-提现 2-提现校验**/
        if(customerWithdrawDto.getWithdrawType()==2){
            return ResponseEntity.ok(Message.REQ_SUCCESS);
        }
        /**冻结资金中添加该笔资金**/
        AppCustomer parameterObj=new AppCustomer();
        parameterObj.setCustomerId(customerWithdrawDto.getCustomerId());
        parameterObj.setCustomerFreezeCapital(customerWithdrawDto.getWithdrawAmount());
        appCustomerMapper.refreshCapital(parameterObj);
        CustomerWithdraw customerWithdraw=new CustomerWithdraw();
        customerWithdraw.setWithdrawId(UUIDUtils.getUuid());
        customerWithdraw.setCustomerId(customerWithdrawDto.getCustomerId());
        customerWithdraw.setCustomerBankId(customerWithdrawDto.getCustomerBankId());
        customerWithdraw.setWithdrawAmount(customerWithdrawDto.getWithdrawAmount());
        customerWithdraw.setWithdrawStatus(3);
        customerWithdraw.setAuditStatus(0);
        customerWithdraw.setCreateTime(new Date());
//        customerWithdraw.setSxf(withdrawSxf);
        customerWithdrawMapper.insertSelective(customerWithdraw);
        return ResponseEntity.ok(Message.REQ_SUCCESS);
    }
    @Transactional
    @Override
    public void onLineRechargeCallback(Response response) throws Exception{
        CustomerOnlineRecharge customerOnlineRecharge=customerOnlineRechargeMapper.selectByTradeNoAndRechargeOrderNum(response.getTradeNo(), response.getOrderNum());
        if(customerOnlineRecharge==null){
            LOGGER.info("回调时间：" + DateUtils.parseToDateTimeStr(new Date()) + " 发生了充值回调找不到数据的情况，order_num：" + response.getOrderNum());
            throw new Exception("回调出异常了");
        }
        /**0-充值成功 1-充值失败 2-提交成功 3-提交失败 4-待提交**/
        customerOnlineRecharge.setRechargeStatus(Integer.valueOf(response.getResultFlag()));
        customerOnlineRecharge.setRechargeStatusMsg(response.getResultMessage());
        customerOnlineRecharge.setTranTime(Long.valueOf(response.getTranTime()));
        customerOnlineRecharge.setUpdateTime(new Date());
        customerOnlineRechargeMapper.updateByPrimaryKeySelective(customerOnlineRecharge);
        /**如果成功 1、修改订单状态 2、客户总资金增加 （充值金额-手续费）**/
        if(response.isSuccess()){
            AppCustomer appCustomer=new AppCustomer();
            appCustomer.setCustomerId(customerOnlineRecharge.getCustomerId());
            //加值金额=充值金额-充值手续费
            appCustomer.setCustomerCapital(customerOnlineRecharge.getRechargeAmount()-customerOnlineRecharge.getPoundage());
            appCustomerMapper.refreshCapital(appCustomer);
        }
    }
    @Transactional
    @Override
    public void submitSuccessCallback(Response response) throws Exception {
        CustomerOnlineRecharge customerOnlineRecharge=customerOnlineRechargeMapper.selectByTradeNoAndRechargeOrderNum(response.getTradeNo(), response.getOrderNum());
        if(customerOnlineRecharge==null){
            LOGGER.info("回调提交成功时间：" + DateUtils.parseToDateTimeStr(new Date()) + " 发生了充值回调提交成功找不到数据的情况，order_num：" + response.getOrderNum());
            throw new Exception("回调出异常了");
        }
        /**0-充值成功 1-充值失败 2-提交成功 3-提交失败 4-待提交**/
        customerOnlineRecharge.setRechargeStatus(Integer.valueOf(response.getResultFlag()) == 0 ? 2 : 3);
        customerOnlineRecharge.setRechargeStatusMsg(response.getResultMessage());
        customerOnlineRecharge.setTranTime(Long.valueOf(response.getTranTime()));
        customerOnlineRecharge.setUpdateTime(new Date());
        customerOnlineRechargeMapper.updateByPrimaryKeySelective(customerOnlineRecharge);
    }

    @Transactional
    @Override
    public void dfQueryByCustomer(String customerId) throws Exception {
        CustomerWithdraw customerWithdraw=new CustomerWithdraw();
        customerWithdraw.setCustomerId(customerId);
        customerWithdraw.setAuditStatus(1);
        customerWithdraw.setWithdrawStatus(2);
        List<CustomerWithdraw> customerWithdrawList=customerWithdrawMapper.selectBySqlWhere(customerWithdraw);
        if(customerWithdrawList.size()>0 && customerWithdrawList!=null){
            for(CustomerWithdraw obj:customerWithdrawList){
                Response response=payRemoteCall.dfQueryMethod(obj.getWithdrawTradeNo());
                AppCustomer appCustomer=new AppCustomer();
                appCustomer.setCustomerId(customerId);
                /**0代付成功|1代付失败|2代付处理中(处理中的 不予处理)**/
                if("0".equals(response.getResultFlag())){
                    //出金成功 扣除客户总资金 撤销客户冻结资金 订单结束
                    appCustomer.setCustomerCapital(-obj.getWithdrawAmount());
                    appCustomer.setCustomerFreezeCapital(-obj.getWithdrawAmount());
                    appCustomerMapper.refreshCapital(appCustomer);
                    obj.setWithdrawStatus(Integer.valueOf(response.getResultFlag()));
                    obj.setResultMessage(response.getResultMessage());
                    obj.setWithdrawTime(new Date());
                    customerWithdrawMapper.updateByPrimaryKeySelective(obj);
                }
                if("1".equals(response.getResultFlag())){
                    //出金失败 撤销冻结资金 订单结束
                    appCustomer.setCustomerFreezeCapital(-obj.getWithdrawAmount());
                    appCustomerMapper.refreshCapital(appCustomer);
                    obj.setWithdrawStatus(Integer.valueOf(response.getResultFlag()));
                    obj.setResultMessage(response.getResultMessage());
                    customerWithdrawMapper.updateByPrimaryKeySelective(obj);
                }

            }

        }
    }

    /**
     * 根据用户分页获取资金记录（入金和出金记录）
     * @param customerWithdrawDto
     * @return
     */
    @Override
    public List<CustomerCapitalVo> getCustomerCapitalRecord(CustomerWithdrawDto customerWithdrawDto) {
        return customerWithdrawMapper.getCustomerCapitalRecord(customerWithdrawDto);
    }

    @Override
    public int getCustomerCapitalRecordCount(CustomerWithdrawDto customerWithdrawDto) {
        return customerWithdrawMapper.getCustomerCapitalRecordCount(customerWithdrawDto);
    }

    /**
     * 保存通道费率信息
     * payType 1网关 2快捷
     * @param payMethodVoList
     */
    @Async("executorPool")
    private void saveRedisFee(List<PayMethodVo> payMethodVoList,String payType){
        try {
            for(PayMethodVo payMethodVo:payMethodVoList){
                Object payMethodVoToJson= JSONObject.toJSON(payMethodVo);
                /**推送完成之后更新首页主力合约列表的合约最新值**/
                if(1==Integer.valueOf(payType)){
                    redisTemplate.opsForHash().put(Constant.PAY_METHOD_KEY_GATEWAY,payMethodVo.getPayMethodName(),payMethodVoToJson.toString());
                }else if(2==Integer.valueOf(payType)){
                    redisTemplate.opsForHash().put(Constant.PAY_METHOD_KEY_QUICK,payMethodVo.getPayMethodName(),payMethodVoToJson.toString());
                }

            }
        }catch (Exception e){
            e.printStackTrace();
            LOGGER.info("saveRedisFee error .............. ");
        }
    }

    @Override
    public List<CustomerWithdraw> checkIsExistWithdraw(String customerId) {
        CustomerWithdraw customerWithdrawParam=new CustomerWithdraw();
        customerWithdrawParam.setCustomerId(customerId);
        customerWithdrawParam.setAuditStatus(0); //未审核
        customerWithdrawParam.setWithdrawStatus(3); //未发起
        List<CustomerWithdraw> customerWithdrawList=customerWithdrawMapper.selectBySqlWhere(customerWithdrawParam);
       /* if(customerWithdrawList.size()>0){
            //存在未审核订单
            return ResponseEntity.ok(Message.WITHDRAW_EXIST_UNAUDITED);
        }*/
        return customerWithdrawList;
    }

    private Long getPayNum(){
        Long orderNoInt;
        String nowDateStr=DateUtils.convertDateToString(new Date());
        String key=Constant.PAY_NO_LOCA+nowDateStr;
        Object keyFalg=redisTemplate.opsForValue().get(key);
        //如果是新的一天 则从新的100000开始
        if(keyFalg==null){
            redisTemplate.opsForValue().set(key,"100000",24, TimeUnit.HOURS);
            orderNoInt=redisTemplate.opsForValue().increment(key,1);
        }else{
            orderNoInt=redisTemplate.opsForValue().increment(key,1);
        }
        return orderNoInt;
    }
}
